This application is based on an application No. 10-302998 filed in Japan, the content of which is hereby incorporated by reference.
(1) Field of the Invention
The present invention relates to a program linking apparatus and a program linking method for linking a plurality of programs that are stored in a plurality of read only semiconductor memories and for referring to subroutines and data.
(2) Description of the Related Art
It has been necessary for embedded microcomputer control systems that store program instructions in read only semiconductor memories (referred to xe2x80x9cROMsxe2x80x9d in this specification) to add and partially replace software after sale due to the complication of the systems.
In this case, the size of the program to be added or replaced, or the size of the data to be used by the program changes, so that the addresses of subroutines in the program and the data that are to be used by the program also change. As a result, when subroutines and export symbols of the program to be added or replaced and remaining programs are referred to each other, the export symbols need to be linked.
Conventionally, programs recorded in ROMs are linked by indicating the locations of the export symbols in a reference table that has been fixedly allocated in a ROM or a RAM using absolute addresses.
The structure of a conventional apparatus that links programs recorded in ROMs is shown in FIG. 48. The apparatus in FIG. 48 includes a ROM-A 101, a ROM-B 102, a RAM 103, a CPU bus 104, and a CPU 105. The ROM-A 101, the ROM-B 102, the RAM 103, and the CPU 105 are connected with each other by the CPU bus 104.
The ROM-A 101 stores a main step 110 and a program A 120. The ROM-B 102 stores a program B 130. The RAM 103 stores data A 140 and data B 150. The CPU 105 executes the programs stored in the ROM-A 101 and the ROM-B 102.
The memory map and the contents of the program A 120 and the data A 140 that is used by the program A 120 are shown in FIG. 49. As shown in FIG. 49, the program A 120 includes a symbol table A 121 and a program instruction part A 122. The symbol table A 121 stores absolute addresses 123, 124, 125, and 126. The absolute addresses 123 and 124 indicate the locations of code export symbols, symbols A 127 and B 128, respectively. The absolute addresses 125 and 126 indicate the locations of data export symbols, symbols C 141 and 0142, respectively. The absolute addresses that indicate the locations of the absolute addressed 123, 124, 125, and 126 are xe2x80x9c0X01000xe2x80x9d, xe2x80x9c0X010004xe2x80x9d, xe2x80x9c0X010008xe2x80x9d, and xe2x80x9c0X01000Cxe2x80x9d, respectively. The program instruction part A 122 stores a program block that is identified by the symbol A 127 and another program block that is identified by the symbol B 128. The absolute addresses that indicate the locations of the symbols A 127 and B 128 are xe2x80x9c0X010010xe2x80x9d and xe2x80x9c0X010200xe2x80x9d, respectively. The data A 140 stores a data block that is identified by the symbol C 141 and another data block that is identified by the symbol D 142. The absolute address that indicates the location of the leading data of the data A 140 is xe2x80x9c0X11000xe2x80x9d. The absolute addresses of the locations of the symbols C 141 and D 142 are xe2x80x9c0X110500xe2x80x9d and xe2x80x9c0X110600xe2x80x9d, respectively. In this specification, the character string xe2x80x9c0Xxe2x80x9d indicates that the following character string is a hexadecimal numeral.
The memory map and the contents of the program B 130 and the data B 150 that is used by the program B 130 are shown in FIG. 50. As shown in FIG. 50, the program B 130 includes a symbol table B 131 and a program instruction part B 132. The symbol table B 131 stores absolute addresses 133, 134, 135, and 136. The program instruction part B 132 stores program blocks that are identified by symbols E 137 and F 138. The data B 150 stores data blocks that are identified by symbols G 151 and H 152. Note that the structure of the program B 130 is the same as the program A 120 and the structure of the data B 150 is the same as the data A 140. More detailed explanation of the program B 130 and the data B 150 will not be given here.
An explanation of operations by the program stored in the main step 110 will be given with reference to the flowchart in FIG. 51. The principle objective of the main step 110 is to control the program block that is identified by the symbol A 127 and the program block that is identified by the symbol E 137 so that the program blocks are executed in this order.
In the main step 110, the content of the address xe2x80x9c0X010000xe2x80x9d, where the absolute address of the symbol A 127 is stored, is extracted and the extracted content is substituted into a variable xe2x80x9cptraxe2x80x9d (step s401) The content of the address xe2x80x9c0X020000xe2x80x9d, where the absolute address of the symbol E 137 is stored, is extracted and the extracted content is substituted into a variable xe2x80x9cptrexe2x80x9d (step s402). Then, the address that the variable xe2x80x9cptraxe2x80x9d indicates is called (step s403), and the address that the variable xe2x80x9cptrexe2x80x9d indicates is called (step s404).
FIG. 52 shows a program that is stored in the program block indicated by the symbol A 127 in the C language. The principle objective of this program is to execute the program block that is identified by the symbol F 138, to substitute a variable xe2x80x9cXXXXXxe2x80x9d into the data block that is identified by the symbol G 151, and to substitute a variable xe2x80x9cYYYYYxe2x80x9d into the data block that is identified by the symbol H 152.
In FIG. 52, the symbol A is defined in a line 501, the content of the address xe2x80x9c0X020004xe2x80x9d, where the absolute address of the symbol F is stored, is substituted into a variable xe2x80x9cptrfxe2x80x9d in a line 502, the content of the address xe2x80x9c0X020008xe2x80x9d, where the absolute address of the symbol G is stored, is substituted into a variable xe2x80x9cptrgxe2x80x9d in a line 503, the content of the address xe2x80x9c0X02000Cxe2x80x9d, where the absolute address of the symbol H is stored, is substituted into a variable xe2x80x9cptrhxe2x80x9d in a line 504, the address that the variable xe2x80x9cptrfxe2x80x9d indicates is called in a line 505, the variable xe2x80x9cXXXXXxe2x80x9d is substituted into the address that the variable xe2x80x9cptrgxe2x80x9d indicates in a line 506, the variable xe2x80x9cYYYYYxe2x80x9d is substituted into the address that the variable xe2x80x9cptrhxe2x80x9d indicates in a line 507, and a return is performed in a line 508.
FIG. 53 shows a program that is stored in the program block indicated by the symbol E 137 in the C language. The principle objective of this program is to execute the program block that is identified by the symbol B 128, to substitute a variable xe2x80x9cZZZZZxe2x80x9d into the data block that is identified by the symbol C 141, and to substitute a variable xe2x80x9cOOOOOxe2x80x9d into the data block that is identified by the symbol D 142. The structure of the program in FIG. 53 is the same as the program in FIG. 52. More detailed explanation will not be given here.
As has been described, the export symbols in programs can be linked to each other by indicating the locations of the export symbols using the absolute addresses in a reference table that has been fixedly allocated in a ROM or a RAM.
According to the aforementioned conventional linking method of programs in a ROM, the export symbols can be statically linked to each other. On the other hand, the locations of the export symbols for mutual reference among programs are indicated using absolute addresses in a reference table that is allocated in a ROM or a RAM, and the absolute addresses of the symbols of a program on the export end are embedded in a program on the import end. As a result, the arrangement of the program on the export end needs to be fixed in the memory space. Meanwhile, the addresses corresponding to symbols are stored using absolute addresses in the reference table, so that the arrangement of the program on the import end needs to be fixed in the memory space. Under the circumstances, a program that is recorded in a ROM is dependent on the memory map of one embedded microcomputer control system, and a program that has been recorded in a ROM in one system cannot be shared by another system having a different memory map.
It is accordingly the object of the present invention to provide a program linking apparatus, a program linking method, and a storage medium that stores a program linking program that enable the content of a program recorded in a ROM to be independent of the memory map of an embedded microcomputer control system and to be shared by another system having a different memory map.
The above-mentioned object may be achieved by a program linking apparatus that includes a plurality of read only semiconductor memories, the read only semiconductor memories having storage areas, which are located in one storage space indicated with one address system, a storage area including at least one program, the program linking apparatus that links and executes a program in one storage area and a program in another storage area, the program linking apparatus that may include: a first semiconductor memory for including a first storage area, which is located in the storage space, the first storage area storing a first program, which has at least one executable instruction and at least one set, each of which corresponds to a different executable instruction and includes an instruction identifier, which identifies a corresponding executable instruction, and an instruction address, which shows a location in the first program of an area where the corresponding executable instruction is stored and is an offset address indicating a relative location with reference to a beginning location of the first program; a second semiconductor memory for including a second storage area, which is located in the storage space and does not overlap the first storage area, the second storage area storing a second program, which has at least one call instruction, each of which calls an executable instruction and includes an instruction identifier for identifying the executable instruction to be called; an absolute address obtaining unit for storing location information, which indicates the beginning location of the first program in the storage space using an absolute address, and for obtaining an absolute address in the storage space where an executable instruction identified by an instruction identifier in a call instruction is stored using the location information and an instruction address that forms one set with the instruction identifier in the call instruction, wherein an absolute address is an address indicated with the first address system; and an executing unit for executing the executable instruction that has been called with the call instruction by executing an executable instruction that is stored in an area indicated by the absolute address that has been obtained.
In the program linking apparatus, a program containing at least one executable instruction and an offset addresses storing the executable instruction are stored in a predetermined location of the first ROM, and another program containing a call instruction that calls the executable instruction is stored in a predetermined location of the second ROM. In addition, whenever the executable instruction is called by the call instruction, an absolute address where the executable instruction is stored is obtained using the offset address and the location information on the location of the first ROM, and the executable instruction is executed using the absolute address, so that symbols can be linked between the programs. As a result, the programs need not to store the absolute addresses in themselves, and the programs recorded in a ROM are independent of the memory map of an embedded microcomputer control system and can be shared by another system having a different memory map.
The above-mentioned object may be also achieved by the program linking apparatus, wherein the absolute address obtaining unit (1) reads the call instruction from the second storage area and extracts the instruction identifier in the read call instruction, (2) extracts the instruction address from the first storage area that forms one set with an instruction identifier in the first storage area matching the extracted instruction identifier, and (3) adds the location information and the extracted instruction address together to obtain the absolute address in the storage space.
In the program linking apparatus, the offset address and the location information on the location of the first ROM are added together, and the addition result is set as the absolute address. As a result, the absolute address can be obtained by a simple calculation.
The above-mentioned object may be also achieved by the program linking apparatus, wherein the absolute address obtaining unit includes: a reference table;
an absolute address creating unit for reading one call instruction from the second storage area, extracting an instruction identifier in the read call instruction, extracting an instruction address from the first storage area that forms one set with an instruction identifier in the first storage area matching the extracted instruction identifier, and adding the location information and the extracted instruction address together to create an absolute address in the storage space; a reference table writing unit for writing a set of the extracted instruction identifier and the created absolute address in the reference table; a repetition control unit for controlling the absolute address creating unit and the reference table writing unit for the call instructions in the second storage area so that extraction of an instruction identifier, creation of an absolute address, and writing in the reference table are repeated; and an absolute address extraction unit for reading a call instruction from the second storage area, extracting an instruction identifier in the read call instruction, and obtaining an absolute address in the storage space by extracting an absolute address that corresponds to the extracted instruction identifier from the reference table.
In the program linking apparatus, the absolute address of the areas where the executable instructions are stored have been calculated, the reference table has stored all the sets of an instruction identifier and an absolute addresses, and whenever the executable instruction is called by the call instruction, a corresponding absolute address is read from the reference table and the executable instruction is executed using the read absolute address. As a result, the offset address needs not to be converted into an absolute address whenever the executable instruction is called, and the obtainment of the absolute address can be sped up.
The above-mentioned object may be also achieved by the program linking apparatus, wherein the absolute address obtaining unit includes: a reference table that includes an area for storing a predetermined number of sets of an instruction identifier and an absolute address; a judging unit for reading a call instruction from the second storage area, extracting an instruction identifier from the read call instruction, and judging whether the extracted instruction identifier is included in the reference table; a registration unit for extracting an instruction address that forms one set with an instruction identifier in the first storage area matching the extracted instruction identifier from the first storage. area, adding the location information and the extracted instruction address to obtain the absolute address in the storage space, and for writing a set of the extracted instruction identifier and the created absolute address in the reference table when the judging unit judges that the extracted instruction identifier is not included in the reference table; and a reading unit for obtaining the absolute address in the storage space by reading an absolute address that corresponds to the extracted instruction identifier from the reference table when the judging unit judges that the extracted instruction identifier is included in the reference table.
The program linking apparatus is provided with the reference table that has the area for storing a predetermined number of sets of an instruction identifier and an absolute address, and whenever the executable instruction is called by the call instruction, it is judged whether the instruction identifier that identifies the executable instruction is included in the reference table. When the instruction identifier is not included in the reference table, the offset address and the location information on the location of the first ROM are added together to obtain the absolute address, and the set of the instruction identifier and the absolute address is written in the reference table. When the instruction identifier is included in the reference table, the absolute address is read from the reference table, and the executable instruction is executed using the obtained, absolute address As a result, all the sets of an instruction identifier and an absolute address need not to be stored in the memory, so that the conversion from an offset address into an absolute address can be sped up and the necessary memory size can be reduced.
The above-mentioned object may be also achieved by the program linking apparatus, wherein each of the sets that are stored in the first storage area further includes an address flag, which indicates that an instruction address in the same set is an offset address, and the absolute address obtaining unit includes: a cache table that has an area for storing a predetermined number of sets of an address flag, an instruction identifier, and an instruction address, wherein an address flag indicates whether an instruction address in the same set is an offset address or an absolute address, an instruction identifier identifies an executable instruction, an instruction address indicates a location of an area where a corresponding executable instruction is stored in the first program, and an instruction address is an offset address when a corresponding address flag indicates an offset address, and an instruction address is an absolute address when a corresponding address flag indicates an absolute address; an instruction identifier extracting unit for reading a call instruction from the second storage area and extracting an instruction identifier in the read call instruction; an address extracting unit for (1) judging whether the extracted instruction identifier is included in the cache table, (2) extracting an address flag and an instruction address that form one set with an instruction identifier matching the extracted instruction identifier from the first storage area when the extracted instruction identifier is not included in the cache table, and (3) extracting an address flag and an instruction address that correspond to the extracted instruction identifier from the cache table when the extracted instruction identifier is included in the cache table; an absolute address creating unit for (1) obtaining the absolute address in the storage space by adding the location information and the extracted instruction address together when the address flag that has been extracted by the address extracting unit indicates an offset address, and (2) obtaining the absolute address in the storage space by setting the extracted instruction address as the absolute address in the storage space when the address flag that has been extracted by the address extracting unit indicates an absolute address; and a cache table writing unit for writing an address flag that indicates an absolute address, the extracted instruction identifier, and the created absolute address in the cache table when the address flag that has been extracted by the address extracting unit indicates an offset address.
In the program linking apparatus, a program stored in the first ROM contains at least one executable instruction, instruction address that stores the executable instruction, and address flag, is provided with a cache table that has an area for storing a predetermined number of sets of an address flag, an instruction identifier, and an instruction address, and whenever the executable instruction is called by the call instruction, it is judged whether the instruction identifier that identifies the executable instruction is included in the cache table. When the instruction identifier is not included in the cache table, the offset address and the location information on the location of the first ROM are added together to obtain the absolute address. When the instruction identifier is included in the cache table, the corresponding address flag and instruction address are extracted from the cache table, it is judged whether the extracted address flag indicates absolute address or offset address. When the extracted instruction address is an offset address, the extracted instruction address and the location information on the location of the first ROM are added together to obtain the absolute address, and the address flag, instruction identifier, and instruction address are written in the cache table. When the extracted instruction address is an absolute address,,the extracted instruction address is used as the absolute address to be obtained. Since the executable instruction is executed using the obtained absolute address, the absolute address of the area of the executable instruction that has been converted in the previous reference may remain in the cache at the time of a following reference even though the sets of the export symbols and the corresponding addresses are not stored in the memory. As a result, the conversion from an offset address into an absolute address can be sped up.
The above-mentioned object may be also achieved by the program linking apparatus, wherein the absolute address obtaining unit includes: a cache table that has an area for storing a predetermined number of sets of a writing flag, an instruction identifier, and an instruction address, wherein a writing flag indicates whether an instruction address in the same set is an offset address or an absolute address, an instruction identifier identifies an executable instruction, an instruction address indicates a location of an area where a corresponding executable instruction is stored in the first program, and an instruction address is an offset address when a corresponding writing flag indicates an offset address, and an instruction address is an absolute address when a corresponding writing flag indicates an absolute address; an instruction identifier extracting unit for reading a call instruction from the second storage area and extracting an instruction identifier in the read call instruction; an address extracting unit for (1) judging whether the extracted instruction identifier is included in the cache table, (2) extracting an instruction address that forms one set with an instruction identifier matching the extracted instruction identifier from the first storage area when the extracted instruction identifier is not included in the cache table, and (3) extracting a writing flag and an instruction address that correspond to the extracted instruction identifier from the cache table when the extracted instruction identifier is included in the cache table; an absolute address creating unit for (1) obtaining the absolute address in the storage space by adding the location information and the extracted instruction address together one of when the extracted instruction identifier is not included in the cache table and when the writing flag that has been extracted by the address extracting unit indicates an offset address, and (2) obtaining the absolute address in the storage space by setting the extracted instruction address as the absolute address in the storage space when the writing flag that has been extracted by the address extracting unit indicates an absolute address; and a cache table writing unit for writing an address flag that indicates an absolute address, the extracted instruction identifier, and the created absolute address in the cache table one of when the extracted instruction identifier is not included in the cache table and when the writing flag that has been extracted by the address extracting unit indicates an offset address.
The program linking apparatus is provided with a cache table having an area for storing a predetermined number of sets of a writing flag, an instruction identifier, and an instruction address, and judges whether the instruction identifier that identifies the executable instruction is included in the cache table whenever the executable instruction is called by the call instruction. When the instruction identifier is not included in the cache table, the offset address and the location information on the location of the first ROM are added together to obtain the absolute address. When the instruction identifier is included in the cache table, the corresponding writing flag and instruction address are extracted from the cache table, and it is judged whether the extracted writing flag indicates absolute address or offset address. When the extracted instruction address is an offset address, the extracted instruction address and the location information on the location of the first ROM are added together to obtain the absolute address, and the writing flag, instruction identifier, and instruction address are written in the cache table. When the extracted instruction address is an absolute address, the extracted instruction address is used as the absolute address to be obtained. Since the executable instruction is executed using the obtained absolute address, the absolute address of the area of the executable instruction that has been converted in the previous reference may remain in the cache at the time of a following reference even though the sets of the export symbols and the corresponding addresses are not stored in the memory. As a result, the conversion from an offset address into an absolute address can be sped up. In addition, the writing flag in the cache table shows whether the address information on the area of the executable instruction is an offset address or an absolute address, so that the export symbol table can be simplified and the export symbol table used in the system that is provided with no cache device can be used. As a result, the same programs can be used regardless of whether a system is provided with a cache device.